var ds="";
var filename="入库信息";
var grid='';
var exportString='';
function huntfors() {
	$('#ss').searchbox({
	    searcher:function(value,name){
	    	tablebill(path,value,null,null);
	    },
	    prompt:'请选择字段后再输入'
	});
}

/***
 * 选择字段查询数据
 * @param value
 * @param name
 */
function searcherGoods(value,name){
	var url=path+'billmaster/getallbillmaster.html?field='+name+"&searchertext="+value;
	url=encodeURI(url);
	url=encodeURI(url);
	$("#billputin").datagrid("load",url);
}
function putinbilldetal(s,d){
	//alert(screen.width+"s"+screen.height);
	$("#putinbilldetal").dialog({    
	    title: s,    
	    width:screen.width*0.78,    
	    height:screen.height*0.64,
	    modal:true,
	    fit:true,
	    cache: true,
        collapsible:true,
        minimizable:true,
        maximizable:true,
        resizable:true,
	    href:"putinbilldetal.jsp",
	    onLoad: function () { 
	    	tablebilltop(path,d,null,null);
	    	billputindetal(path,d,null,null);
        } ,
        onClose: function () {
        	editRow = undefined;
            },
            buttons: [{
                text: '确认',
                id:'ok',
                iconCls: 'icon-ok',
                handler: function () {
                	$.messager.confirm('确认对话框', '您确认进行此操作吗？', function(r){
                		if(r){
                		var arrname=['客户姓名','物品名称','物品数量','当前序列码','货架','货架位置'];
        			    if(yz("billputindetal",arrname)==0){
                    	    if(ds=="see"){
                    	    	
                    	    }else{
                    	    	editRow1 = undefined;    
                    	    	$("#billputindetal").datagrid("acceptChanges");   
                    	    	$("#billputindetal").datagrid("unselectAll"); 	
                    	    	savedate(this);
                    	    }
        			    	
        			    }
                		}
                	});
                	
                }
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#putinbilldetal').dialog('close');
                }
            }]
        
	});    
	if(ds=="see"){
		$(".dialog-button").hide();
	}else{
		$(".dialog-button").show();
	}
	
}
var j=0;
var a="";
var editRow=undefined; //定义全局变量：当前编辑的行
function tablebill(s1,cs,y,s){
	var uri="";
	var data=null;
	if(y!=null||s!=null){
		uri=s1+'billmaster/querybillmaster.html?filed=入库单&&y='+y+'&&s='+s;
	}else{
		uri=s1+'billmaster/getallbillmaster.html';
	}
	//alert(uri);
	var datagrid; //定义全局变量datagrid            
	  uri=encodeURI(uri);
	  uri=encodeURI(uri);         
	  grid=datagrid=$("#billputin").datagrid({
	  	url:uri,  
	    loadMsg:'数据加载中请稍后……',  
	    pagination: true, 
	    height:480,
	    remoteSort:false,
	    fit:true,
	    pageList: [15,20,30,40,1000000],
	    pageSize: 15,
	    rownumbers: true,  
	    fitColumns:true,
	    onAfterEdit: function (rowIndex, rowData, changes) {  
	    	//endEdit该方法触发此事件        
	    	console.info(rowData);  
	    	editRow = "";
	    	data=rowData;
	    	},
	    	 onLoadSuccess:function(date){
	    		if(role==1){ //如果角色是guest 不能编辑数据
	 	    		$(" .datagrid-toolbar").hide();
	 	    		$('#ok').linkbutton('disable');
	 	    	}
	 	    	$(".datagrid-header-check input[type='checkbox']").attr("disabled","disabled");
	 	    },
	 	 
	    	onClickRow:function(rowIndex, rowData){
		    	if(rowData.states=='已完成'){
		    		$("#billputin").datagrid("unselectRow",rowIndex);
		    	} 
		    },
		    onCheck:function(rowIndex, rowData){
		    	if(rowData.states=='已完成'){
		    		$("#billputin").datagrid("unselectRow",rowIndex);
		    	}
	    	},
	    columns:[[ 
            {field:'id1',checkbox:true,title: '' },
			{field:'billno',title: '库存编号',align: 'center',width:95,sortablebill:true,
				formatter:function(value,rowData,rowIndex){
	        		var sno=value+"";
	                return sno; 
	 	           },
				editor: { type: 'validatebox', options: { required: true} }
			},
			
			{field:'createname',title: '操作人',align: 'center',width:65,sortablebill:true},
			{field:'createid',title: '添加人ID',align: 'center',width:65,sortablebill:true,hidden:true},
			{field:'bilddate',title: '完成时间',align: 'center',width:65,sortablebill:true,
				formatter:function(value,rowData,rowIndex){
	        		var s="";
	        		if(value=="当前时间"){
	        			s=value;
	        		}else{
	        			s=value;
	        		}
	                return s; 
	 	           }	
			},  
			{field:'asd',title: '完成时间1',align: 'center',width:65,sortablebill:true,
				hidden:true	
			},  
			{field:'states',title: '入库状态',align: 'center',width:65,sortable:true   	
				},
				{field:'remark',title: '备注',align: 'center',width:65,sortablebill:true,
					editor: { type: 'textarea', options: {
						width:'200px',
						height:'200px',
						required: false} 
				    }	
				}, 
			{field:'ids',title: '查看记录',align: 'center', 
			    formatter:function(value,rowData,rowIndex){
			        return "<button href='#' onclick='show("+rowData.id+")'>查看</button>"; 
			   },width:65,sortablebill:true  
			}
	    ]],
	    singleSelect : false,
	    selectOnCheck: true,
	    checkOnSelect: true,
	    rowStyler: function(index,row){
			if (row.states=='已完成'){
				return 'background-color:#F0F0F0;color:gray;';
			}
		},
	    toolbar: [{
			iconCls: 'icon-add',
			text:'新增',
			handler: function(){
				ds="";
				$("#tag").val(0);
				$("#id").val(null);
//				j++;
//				a= "HK"+formatDateTime(new Date())+preZeroFill(j, 6);
//				if (editRow != undefined) {
//					alert("请保存或取消更改当前修改的数据后再添加");
//                    $("#billputin").datagrid('endEdit', editRow);
//                }
//				 if (editRow == undefined) {
					 putinbilldetal("入库详情",0);
//                }
			}
	    
				
		},'-',
		{ text: '编辑', iconCls: 'icon-edit', handler: function () {
			ds="";
			$("#tag").val(1);
			var rows=$("#billputin").datagrid("getSelections");
			var ids = [];
			for (var i = 0; i < rows.length; i++) {
		        ids.push(rows[i].id); //注意修改你的id列
		    }
			if(rows.length==0){
				alert("请选择数据！");
				return false;
			}if(rows.length>1){
				alert("请选中一行数据进行编辑");
				return false;
			}
			putinbilldetal("入库详情",rows[0].id);
			
		 }
		},'-',{
			iconCls: 'icon-remove',
			text:'删除',
			handler: function(){
					delmaindate();
				
			}
		},'-',{ 
			iconCls: 'icon-ok',
			text:'提交',
			id:'mainsubmit',
			handler: function(){ 
				mainsubmit();
			}
		
			},'-',{
				iconCls: 'icon-redo',
				text:'导出',
				id:'mainexp',
				handler: function(){ 
					mainexp();
				}
			}
		]
	});
//	  var p = $('#billputin').datagrid('getPager'); 
//	    $(p).pagination({ 
//	        beforePageText: '第',//页数文本框前显示的汉字 
//	        afterPageText: '页    共 {pages} 页', 
//	        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
//	    }); 
} 


function preZeroFill (num, size) {
    if (num >= Math.pow(10, size)) { //如果num本身位数不小于size位
        return num.toString();
    } else {
        var _str = Array(size + 1).join('0') + num;
        return _str.slice(_str.length - size);
    }
}

function show(d){
	ds="see";
	putinbilldetal("入库详情",d);
}
var cur="";
var cur1="";
var editRow1=undefined;
function billputindetal(s1,cs,y,s){
	var uri="";
	var data=null;
	uri=path+'billdetail/querybilldatebyparentid.html?billtype=入库单&parentid='+cs;
	var datagrid1; //定义全局变量datagrid            
  var onl=null;
  uri=encodeURI(uri);
  uri=encodeURI(uri);
  datagrid1 =$("#billputindetal").datagrid({
	    url:uri,
	    //queryParams:{},  
	    loadMsg:'数据加载中请稍后……', 
	    height:screen.height*0.5,
	    remoteSort:false,
	    rownumbers: false, 
	    singleSelect:true,
	    fitColumns:true,
	    onAfterEdit: function (rowIndex, rowData, changes) {  
//	    	putinbilldetal("入库详情",data);
	    	//endEdit该方法触发此事件        
//	    	console.info(rowData);  
//	    	editRow1 = "";
//	    	data=rowData;
	    	},
	  
		onDblClickCell: function (rowIndex, rowData) {
			if(ds=="see"){
				
			}else{
	    	editRow1 = undefined;    
			datagrid1.datagrid("acceptChanges"); 
	    	datagrid1.datagrid("beginEdit", rowIndex);    
    		editRow1 = rowIndex;  
			}
	    	 
	    },
	    
	    columns:[[ 
			{field:'clientname',title: '客户姓名',align: 'center',width:85,sortablebill:true,
				editor: { type: 'combogrid', options: {
					url:path+'clientinfo/getallClientinfo.html?a=1',  
					panelWidth:300,
					panelHeight:340, 
					idField:'clientname',    //主键是ID
				    textField:'clientname',    //文本显示是姓名
				    pagination:true,
				    fitColumns:true,
				    mode:'remote',
				    pageSize:10,
				    pageList:[10,15,20],
					columns:[[    
				                {field:'id',title:'ID',width:60,hidden:true},    
				                {field:'clientname',title:'姓名',width:100},    
				                {field:'tel',title:'电话',width:160,hidden:true}   
				            ]],
				            onSelect: function(rowIndex,rowData){
						    	 var drow = $('#billputindetal').datagrid('getSelected');
				                 var index = $('#billputindetal').datagrid('getRowIndex', drow);     
						    	setTimeout(function () {
						    	    editRow1 = undefined;    
					 				datagrid1.datagrid("acceptChanges");   
					 				datagrid1.datagrid("unselectAll"); 
					                datagrid1.datagrid('updateRow', { index: index, row: {clientid:rowData.id,clientname:rowData.clientname} });
					                datagrid1.datagrid("acceptChanges"); 
					                $('#billputindetal').datagrid('endEdit', index).datagrid('refreshRow', index).datagrid('selectRow', index).datagrid(
				                                'beginEdit', index);
						    	},10);
				            }
				},
				}
			},
			{field:'clientid',title: '客户ID',align: 'center',width:85,sortablebill:true,hidden:true},
			{field:'assetdescription',title: '资产描述',align: 'center',width:85,sortablebill:true,hidden:true},
			{field:'goodid',title: '物品ID',align: 'center',width:85,sortablebill:true,hidden:true},
			{field:'goodname',title: '物品名称',align: 'center',width:85,sortablebill:true,
				editor: { type: 'combogrid', options: { 
					url:path+'goods/getallgoods.html?a=1',  
					panelWidth:300, 
					panelHeight:340,
					idField:'goodsname',    //主键是ID
				    textField:'goodsname',    //文本显示是姓名
				    pagination:true,
				    fitColumns:true,
				    pageSize:10,
				    pageList:[10,15,20],
					required: true,
					mode:'remote',
//				    onChange:function(newValue, oldValue){
//				    	if(newValue=="请必选"){
//				    		newValue="";
//				    	}
//				    	cur1=path+'goods/getallgoods.html?page=1&rows=10&field=goodsname&searchertext='+newValue;
//				    	cur1 = encodeURI(cur1);
//				    	cur1 = encodeURI(cur1);
//				    	var str=[];
//				    	$.ajax({  
//				    	      type:'post',      
//				    	      url:cur1,  
//				    	      cache:false,
//				    	      async: false, //同步
//				    	      dataType:'json',
//				    	      success:function(data){
//				    	    	  str=data;	
//				    	     }});
//				        $(this).combogrid("grid").datagrid("loadData", str); 
//				    },
				    columns:[[    
				                {field:'id',title:'ID',width:60,hidden:true},    
				                {field:'goodsname',title:'物品名称',width:100},    
				                {field:'billno',title:'编码',width:160,hidden:true}, 
				                {field:'specifications',title:'物品规格',width:160,},
				                {field:'units',title:'物品单位',width:160}
				            ]],
				    
				    onSelect: function(rowIndex,rowData){
				    	 var drow = $('#billputindetal').datagrid('getSelected');
		                 var index = $('#billputindetal').datagrid('getRowIndex', drow);     
				    	var ed=null;
			                // var d0=jQuery(ed[0].target).val();
			                 ed= $('#billputindetal').datagrid('getEditor', {index:index,field:'goodnumber'});
			                 var goodnumberval=ed.target.val();
			                 ed= $('#billputindetal').datagrid('getEditor', {index:index,field:'goodname'});
			                 var goodnameval=ed.target.val();
			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'snno'});
			                 var snnoval=ed.target.val();
			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'clientname'});
			                 var couriernumberval=ed.target.val();
//			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'specifications'});
//			                 var specificationsval=ed.target.val();
			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'remark'});
			                 var remarkval=ed.target.val();
                       
				    	setTimeout(function () {
				    	    editRow1 = undefined;    
			 				datagrid1.datagrid("acceptChanges");   
			 				datagrid1.datagrid("unselectAll"); 
			                 datagrid1.datagrid('updateRow', { index: index, row: {goodid:rowData.id,goodsbillno:rowData.billno,goodname:rowData.goodsname,unit:rowData.units,specifications:rowData.specifications} });
			                 datagrid1.datagrid("acceptChanges"); 
			                 $('#billputindetal').datagrid('endEdit', index).datagrid('refreshRow', index).datagrid('selectRow', index).datagrid(
		                                'beginEdit', index);
				    	},10);
//				    	
					}
				} }
			},
			{field:'specifications',title: '规格型号',align: 'center',width:85,sortablebill:true},
			//{field:'beiyon',title: '库存编号',align: 'center',width:85,sortablebill:true},
			
			{field:'goodsbillno',title: '物品编号',align: 'center',width:85,sortablebill:true,hidden:true},
			{field:'goodnumber',title: '物品数量',align: 'center',width:85,sortablebill:true,
				editor: { type: 'numberbox', options: { required: true} }
			},
			{field:'unit',title: '物品单位',align: 'center',width:85,sortablebill:true},
			{field:'snno',title: 'SN',align: 'center',width:85,sortablebill:true,
				editor: { type: 'validatebox', options: { required: true} }
			},
			{field:'repartoyname',title: '仓库名称',align: 'center',width:65,sortablebill:true},
			{field:'repartoyrack',title: '货架',align: 'center',width:100,sortablebill:true,
				editor: { type: 'combotree', options: {required: true ,
					url:path+'repertory/getallrepertory.html',  
					animate:false,
					lines:true,
					idFiled:'titles',
					textFiled:'titles',
					parentField:'parentid',
					onClick: function(node){
						
						var node1=$(this).tree('getParent',node.target);
						
						if(node1==null){
							     var drow = $('#billputindetal').datagrid('getSelected');
				                 var index = $('#billputindetal').datagrid('getRowIndex', drow);
				                 editRow1 = undefined;    
				 				datagrid1.datagrid("acceptChanges");   
				 				datagrid1.datagrid("unselectAll"); 
				                 datagrid1.datagrid('updateRow', { index: index, row: {repartoyrack:""} });
				                 datagrid1.datagrid("acceptChanges"); 
				                 $('#billputindetal').datagrid('endEdit', index).datagrid('refreshRow', index).datagrid('selectRow', index).datagrid(
			                                'beginEdit', index);
					    	
							alert("请选择仓库下的货架");
							
						}else{
							var drow = $('#billputindetal').datagrid('getSelected');
			                 var index = $('#billputindetal').datagrid('getRowIndex', drow);
			                 
			                 
			                 var ed=null;
			                // var d0=jQuery(ed[0].target).val();
			                  ed= $('#billputindetal').datagrid('getEditor', {index:index,field:'goodnumber'});
			                 var goodnumberval=ed.target.val();

//			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'specifications'});
//			                 var specificationsval=ed.target.val();
			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'snno'});
			                 var snnoval=ed.target.val();
			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'couriernumber'});
			                 var couriernumberval=ed.target.val();
			                 ed = $('#billputindetal').datagrid('getEditor', {index:index,field:'remark'});
			                 var remarkval=ed.target.val();
 
			                 editRow1 = undefined;    
			                 $('#billputindetal').datagrid('updateRow', { 
			                	 index: index, 
			                	 row: {repartoyrack:node.text,
			                		   repartoyname:node1.text,
			                		   goodnumber:goodnumberval,
			                		   snno:snnoval,
			                		   couriernumber:couriernumberval,
			                		   remark:remarkval
			                		   
			                	 } 
			                 });
			                 $('#billputindetal').datagrid('endEdit', index);
			                 $('#billputindetal').datagrid('refreshRow', index);
			                 $('#billputindetal').datagrid('selectRow', index);
			                 $('#billputindetal').datagrid('beginEdit', index);
				    	
					}
					}
				}
				}	
			},
			{field:'repartoyaddress',title: '货架位置',align: 'center',width:65,sortablebill:true,
				editor: { type: 'combobox', options: { 
					valueField: 'label',
					textField: 'value',
					panelHeight:70,
					data: [{
						label: '上层',
						value: '上层'
					},{
						label: '中层',
						value: '中层'
					},{
						label: '下层',
						value: '下层'
					}],required: true
				}
				}
			},
			{field:'couriernumber',title: '快递单号',align: 'center',width:65,sortablebill:true,
				editor: { type: 'validatebox', options: { required: false} }	
			},
			 
			{field:'remark',title: '备注',align: 'center',width:65,sortablebill:true,
				editor: { type: 'validatebox', options: { required: false} }	
			},  
			{field:'ids',title: '功能',align: 'center', 
			    formatter:function(value,rowData,rowIndex){
			    	if(ds=="see"){
				    	return '';
				    }else{
				    	return "<a href='#' onclick='del("+rowIndex+","+rowData.id+","+JSON.stringify(rowData)+")'>删除</a>";
				    }
			   },width:65,sortablebill:true  
			}
	    ]],
	    onLoadSuccess:function (rowIndex, rowData) { 
			 if(ds=="see"){  //禁用按钮
				// $(" .datagrid-toolbar").hide();
				 $('#dtladd').linkbutton('disable');
				
			 }    
        },
	    toolbar: [{
			iconCls: 'icon-add',
			text:'新增',
			id:"dtladd",
			handler: function(){
				if (editRow1 != undefined) {
                    $("#billputindetal").datagrid('endEdit', editRow1);
                }
				var arrname=['客户姓名','物品名称','物品数量','当前序列码','货架','货架位置'];
			    if(yz("billputindetal",arrname)==0){
			    	editRow1 = undefined;    
    				datagrid1.datagrid("acceptChanges");   
    				datagrid1.datagrid("unselectAll");
			    	if (editRow1 == undefined) {
						$("#billputindetal").datagrid('appendRow', {        
		                        	clientname:'请必选',
		                        	goodsbillno:'请必填',
		                        	goodname:'请必选',
		                        	goodnumber:'0',
		                        	specifications:"请必选",
		                        	unit:'请必填',
		                        	snno:'可填',
		                        	repartoyname:'请必填',
		                        	repartoyrack:'请必选',
		                        	repartoyaddress:'请必选',
		                        	couriernumber:'',
		                        	remark:''
		                      
		                    }); 
						editRow1 = 0; 
						
                }
				
					   
	 				//datagrid1.datagrid("acceptChanges");   
	 				//datagrid1.datagrid("unselectAll"); 
	               }
			}
				
		}, '-',{ id:"dtladd",text: '保存', iconCls: 'icon-save', handler: function () {
				var arrname=['客户姓名','物品名称','物品数量','当前序列码','货架','货架位置'];
			    if(yz("billputindetal",arrname)==0){
    				editRow1 = undefined;    
    				datagrid1.datagrid("acceptChanges");   
    				datagrid1.datagrid("unselectAll"); 	
                }

			 }
			}
		]
	});
	  var p = $('#billputindetal').datagrid('getPager'); 
	    $(p).pagination({ 
//	        pageSize: 20,//每页显示的记录条数，默认为10 
//	        pageList: [10,20,30,40,50],//可以设置每页记录条数的列表 
	        beforePageText: '第',//页数文本框前显示的汉字 
	        afterPageText: '页    共 {pages} 页', 
	        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
	    }); 
} 
function yz(id,arrname) {
	
	var drow = $('#'+id).datagrid('getSelected');
    var index = $('#'+id).datagrid('getRowIndex', drow);
    var ed = $('#'+id).datagrid('getEditors',index);
    var vv="";
    var i=0;
    var i1=0;
    $.each(ed, function(idx, obj) {
       try {
    	   vv=obj.target.combo('getText');
		} catch (e) {
		   vv=obj.target.val();
		}
		
		i1=0;
		if(i<arrname.length){
		if(vv.trim()=="0"||vv.trim()=="请必填"||vv.trim()=="请必选"||vv.trim()==""||vv.trim()==null){
			alert("请设置【"+arrname[i]+"】的值!");
			i1=1;
			return false;
		}}
		i++;
    });    
    
    return i1;
}
function jsonDateFormat(jsonDate) {
	   //json日期格式转换为正常格式
	    try {
	        var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));
	        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
	        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	        var hours = date.getHours();
	        var minutes = date.getMinutes();
	        var seconds = date.getSeconds();
	        var milliseconds = date.getMilliseconds();
	        return   month + "/" + day +"/"+ date.getFullYear() +" " + hours + ":" + minutes + ":" + seconds + "." + milliseconds;
	    } catch (ex) {
	        return "";
	    }
	}

function formatDateTime(date) {  
    var y = date.getFullYear();  
    var m = date.getMonth() + 1;  
    m = m < 10 ? ('0' + m) : m;  
    var d = date.getDate();  
    d = d < 10 ? ('0' + d) : d;  
    var h = date.getHours();  
    var minute = date.getMinutes();  
    minute = minute < 10 ? ('0' + minute) : minute; 
    var s = date.getSeconds() + 1;  
    s = s < 10 ? ('0' + s) : s;
    return y + '' + m + '' + d+''+h+''+minute+''+s;  
}; 

var editRow2=undefined; //定义全局变量：当前编辑的行
function tablebilltop(s1,cs,y,s){
  var uri="";
  var data=null;
  if(cs!=0){
		$.ajax({  
		      type:'post',      
		      url:path+'billmaster/getbillmaster.html?cs='+cs,  
		      cache:false,  
		      dataType:'json',  
		      success:function(data){
		    	$("#billno").val(data[0].billno)
			    $("#remark").val(data[0].remark);
			    $("#id").val(data[0].id);
		      },
			    error:function(){ 
			    	
			    }
		  });
  }
  else{
	 
  $.ajax({  
      type:'post',      
      url:path+'billmaster/getid.html',  
      cache:false,  
      dataType:'json',  
      success:function(data){
    	    $("#createname").text(crtname);
		    $("#asd").text('当前时间');
		    $("#remark").val("");
      },
	    error:function(){ 
	    	
	    }
  });}
}

function savedate(obj){
  var billtype='入库单';
  var remark=$("#remark").val();
  var tag=$("#tag").val();
  var id=$("#id").val();
  var datas=$("#billputindetal").datagrid('getRows');
  var rowslist=JSON.stringify(datas);
  var param="tag="+tag+"&id="+id+"&billtype="+billtype+"&remark="+remark+"&rows="+rowslist
  param = encodeURI(param);
  param = encodeURI(param);
  $.ajax({  
      type:'post',      
      url:path+'billdetail/savebilldate.html',  
      data:param, 
      cache:false,   
      success:function(data){
    	  $('#billputin').datagrid('reload');
    	  if(tag==0){
    		  alert("新增数据成功");
    	  }else if(tag==1){
    		  alert("变更数据成功");
    	  }
    	  $('#putinbilldetal').window('close');
      	
      },
      error: function(jqXHR, textStatus, errorThrown) {
    	  switch (jqXHR.status){  
          case(500):  
              alert("服务器系统内部错误");  
              break;  
          case(401):  
              alert("未登录");  
              break;  
          case(403):  
              alert("无权限执行此操作");  
              break;  
          case(408):  
              alert("请求超时");  
              break;  
          default:  
              alert("未知错误");  
      }  
      }
  }); 
}

/**删除主数据 ***/
function delmaindate(){
	var rows=$("#billputin").datagrid("getSelections");
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].id); //注意修改你的id列
    }
	if(rows.length==0){
		alert("请选择数据！");
		return false;
	}
	$.messager.confirm('确认对话框', '您想要删除此数据吗？', function(r){
		if (r){
	
	var param="rows="+JSON.stringify(rows)+"&ids="+ids.join(',');
	  param = encodeURI(param);
	  param = encodeURI(param);	
	$.ajax({  
	      type:'post',      
	      url:path+'billdetail/upatebilldatebyids.html?new='+Math.random(),  
	      data:param, 
	      cache:false,   
	      success:function(data){
	    	  $('#billputin').datagrid('reload');
	    	  alert("删除数据成功");  	
	      },
	      error: function(jqXHR, textStatus, errorThrown) {
	    	  switch (jqXHR.status){  
	          case(500):  
	              alert("服务器系统内部错误");  
	              break;  
	          case(401):  
	              alert("未登录");  
	              break;  
	          case(403):  
	              alert("无权限执行此操作");  
	              break;  
	          case(408):  
	              alert("请求超时");  
	              break;  
	          default:  
	              alert("未知错误");  
	      }  
	      }
	  }); 
		}
	});
}
/******主表提交数据******/
function mainsubmit(){
	var rows=$("#billputin").datagrid("getSelections");
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].id); //注意修改你的id列
    }
	if(rows.length==0){
		alert("请选择数据！");
		return false;
	}
	$.messager.confirm('确认对话框', '您想要提交选中数据吗？', function(r){
    if (r){
	var param="rows="+JSON.stringify(rows)+"&ids="+ids.join(',')+"&billtype=入库单";
	param = encodeURI(param);
	  param = encodeURI(param);	
	$.ajax({  
	      type:'post',      
	      url:path+'billdetail/upatebilldatesubmitbyids.html?new='+Math.random(),  
	      data:param, 
	      cache:false,   
	      success:function(data){
	    	  $('#billputin').datagrid('reload');
	    	  alert("提交数据成功");  	
	      },
	      error: function(jqXHR, textStatus, errorThrown) {
	    	  switch (jqXHR.status){  
	          case(500):  
	              alert("服务器系统内部错误");  
	              break;  
	          case(401):  
	              alert("未登录");  
	              break;  
	          case(403):  
	              alert("无权限执行此操作");  
	              break;  
	          case(408):  
	              alert("请求超时");  
	              break;  
	          default:  
	              alert("未知错误");  
	      }  
	      }
	  }); 
		}
	});
}

/****
 * 导出当页
 */
function mainexp(){
	var rows=$("#billputin").datagrid("getSelections");
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].id); //注意修改你的id列
    }
	if(rows.length==0){
		alert("请选择数据！");
		return false;
	}
	var  url=path+"billdetail/getexporttoexcl.html?ids="+ids.join(',')+"&billtype=入库单&new="+Math.random(); 
	url = encodeURI(url);
	url = encodeURI(url);
	window.open(url);
}
/***
 * 删除新增表单中的明细数据 
 * @param index
 * @param id 当前行的id
 */
function del(index,rowid,rowsrt){
	//alert(rowsrt)
	var rows=JSON.stringify(rowsrt);
	var param="rows="+rows+"&id="+rowid;
	  param = encodeURI(param);
	  param = encodeURI(param);	
	$.messager.confirm('确认对话框', '您想要删除此数据吗？', function(r){
		if (r){
			if(rowid!=null){
				 $.ajax({  //ajax删除明细数据
				      type:'post',      
				      url:path+'billdetail/delbilldate.html',  
				      data:param, 
				      cache:false,   
				      success:function(data){
				    	  if(data=='ok'){
				    		  $("#billputindetal").datagrid('deleteRow',index);	
				    	  }else{
				    		  alert("删除失败！");
				    		  return false;
				    	  }
				    	  
				      },
				      error: function(jqXHR, textStatus, errorThrown) {
				    	  switch (jqXHR.status){  
				          case(500):  
				              alert("服务器系统内部错误");  
				              break;  
				          case(401):  
				              alert("未登录");  
				              break;  
				          case(403):  
				              alert("无权限执行此操作");  
				              break;  
				          case(408):  
				              alert("请求超时");  
				              break;  
				          default:  
				              alert("未知错误");  
				      }  
				      }
				  });
			}else{
				$("#billputindetal").datagrid('deleteRow',index);	
			}
		}
	});  
}